﻿using System;
using System.Management;
using SSM.BusinessLayer.Enums;

namespace SSM.BusinessLayer.Monitors
{
	public class SensorMonitor : BaseMonitor
	{
        #region Properties

		public ManagementObjectSearcher WmiSearcher { get; set; }
        public SensorMonitorType Type { get; set; }

		#endregion

		#region Constructor

		public SensorMonitor(SensorMonitorType monitorType)
		{
			Start(monitorType);
		}

		private void Start(SensorMonitorType monitorType)
		{
			String query = String.Empty;

			switch (monitorType)
			{
				case SensorMonitorType.CpuTemp:
				case SensorMonitorType.MotherboardTemp:
				case SensorMonitorType.MemoryTemp:
				case SensorMonitorType.DiskTemp:
					query = "SELECT * FROM Win32_TemperatureProbe";
					break;
				case SensorMonitorType.CpuFan:
				case SensorMonitorType.MotherboardFan:
					query = "SELECT * FROM Win32_Fan";
					break;
			}

			WmiSearcher = new ManagementObjectSearcher(query);
			Type = monitorType;
		}

		#endregion

		#region Override BaseMonitor

		public override Single GetNextValue()
		{
			LastValue = GetWmiObjectValue();
			LastCheck = DateTime.Now;

			return LastValue;
		}

		public override String Title
		{
			get { return Type.ToString(); }
		}

		private Single GetWmiObjectValue()
		{
			Single value = 0;

			return value;
		}

		#endregion
	}
}